/*
 *  Copyright 2015-2016, RenGu Technology (BeiJing) Co., Ltd.
 *  All right reserved.
 *
 *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  THE CONTENTS OF THIS FILE MAY NOT BE DISCLOSED TO THIR PARTIES,
 *  COPIED OR DUPLICATED IN ANY FORM, IN WHOLE OR IN PART,
 *  WITHOUT THE PRIOR WRITTEN PERMISSION OF RENGU TECHNOLOGY (BeiJing) CO., LTD.
 *
 *  AcctStatusEnum
 *
 *  Edit History:
 *      lizhangtao Created on 2020年04月09日
 *
 */
package cc.rengu.igas.acct.common.enums;


import cc.rengu.utility.base.StringUtil;

/**
 * 账户状态枚举
 *
 * @author lizhangtao
 */
public enum AcctStatusEnum {
    //正常状态账户
    NORMAL("00", "正常"),
    //冻结状态，只入不出
    FREEZE("01", "冻结"),
    //注销状态不入不出
    CANCEL("02", "注销");
    private String acctStatus;
    private String acctDesc;

    AcctStatusEnum(String acctStatus, String acctDesc) {
        this.acctStatus = acctStatus;
        this.acctDesc = acctDesc;
    }

    public String getAcctStatus() {
        return acctStatus;
    }

    public String getAcctDesc() {
        return acctDesc;
    }


    public static AcctStatusEnum getInstance(String acctStatus) {
        switch (acctStatus) {
            case "00":
                return NORMAL;
            case "01":
                return FREEZE;
            case "02":
                return CANCEL;
            default:
                return null;
        }
    }

    /**
     * 判断当前状态下是否可变更为某状态
     *
     * @param acctStatus
     * @return -1不允许变更，0可变更，1不需要变更
     */
    public int isOk(String acctStatus) {
        if (StringUtil.isNullorEmpty(acctStatus)) {
            return -1;
        }
        if (acctStatus.equals(this.acctStatus)) {
            //不需要变更
            return 1;
        } else {
            //00正常->(冻结操作)->01冻结；00正常->(注销操作)->02注销
            if (AcctStatusEnum.NORMAL.acctStatus.equals(this.acctStatus)) {
                if (acctStatus.equals(AcctStatusEnum.FREEZE.acctStatus) ||
                        acctStatus.equals(AcctStatusEnum.CANCEL.acctStatus)) {
                    return 0;
                } else {
                    return -1;
                }
            }
            //01冻结->(解冻操作)—>00正常；01冻结->(注销操作)—>02注销
            else if (AcctStatusEnum.FREEZE.acctStatus.equals(this.acctStatus)) {
                if (acctStatus.equals(AcctStatusEnum.NORMAL.acctStatus) ||
                        acctStatus.equals(AcctStatusEnum.CANCEL.acctStatus)) {
                    return 0;
                } else {
                    return -1;
                }
            }
            //02注销->(X)不能进行任何操作
            else {
                return -1;
            }
        }


    }
}
